package logic

import (
	"context"
	"shenzhou/B/srv/car"
	"shenzhou/B/srv/internal/svc"
	"shenzhou/B/srv/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *car.GoodsAddRequest) (*car.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line

	g := mysql.Goods{
		GoodsTitle:  in.GoodsTitle,
		GoodsPrice:  float64(in.GoodsPrice),
		GoodsCover:  in.GoodsCover,
		GoodsStock:  int(in.GoodsStock),
		GoodsStatus: int(in.GoodsStatus),
		LikeCount:   int(in.LikeCount),
	}
	err := g.Create()
	if err != nil {
		logx.Error("商品发布失败")
		return nil, err
	}
	return &car.GoodsAddResponse{GoodsId: int64(g.ID)}, nil
}
